package org.example.physics_engine.geometry.shapes;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.example.physics_engine.body.Mass;
import org.example.physics_engine.body.Transform;
import org.example.physics_engine.geometry.*;

//抽象shape类
@Getter
@Setter
@NoArgsConstructor
//使用Jackson用来序列化和反序列化
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class", visible = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class AbstractShape implements Convex{

    //物体的旋转/位移
    protected Transform transform = new Transform();
    //物体的缩放比率
    protected int rate = 1;

    protected AbstractShape(Transform transform) {
        this.transform = transform;
    }

    //物体的缩放
    public abstract void zoom(int rate);

    //返回对应图形的Box
    public abstract AxisAlignBoundingBox createAABB();

    //投影，返回投影的范围Interval
    //参数是要投影到的向量
    public abstract Interval project(Vector2d axis);

    //根据物体密度求算质量
    public abstract Mass createMass(double density);

    //本shape绕着一点做旋转
    //参数有旋转角度的cos、sin值和旋转点坐标
    public void rotate(double cos, double sin, double x, double y) {
        transform.rotate(cos, sin, x, y);
    };

    //本shape绕着一点做旋转
    //参数有旋转角度theta和旋转点坐标
    public void rotate(double theta, double x, double y) {
        transform.rotate(theta, x, y);
    };

    //本shape按照给定坐标平移
    public void translate(double x, double y) {
        transform.translate(x, y);
    }

    //本shape按照给定向量平移
    public void translate(Vector2d vector) {
        transform.translate(vector);
    }

    //获得以参数为原点时本shape的坐标
    public Vector2d getPoint(Vector2d origin) {
        return transform.getInverseTransformed(origin);
    }
}
